package com.itfitness.timepicker

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.NumberPicker
import android.widget.Toast
import androidx.databinding.DataBindingUtil
import com.itfitness.timepicker.databinding.ActivityMainBinding
import java.util.*

class MainActivity : AppCompatActivity() {
    private lateinit var activityMainBinding:ActivityMainBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        activityMainBinding = DataBindingUtil.setContentView<ActivityMainBinding>(this,R.layout.activity_main)
        activityMainBinding.lifecycleOwner = this
        activityMainBinding.btShowTimeDialog.setOnClickListener {
            DialogFactory.createTimePickerDialog(this@MainActivity) { year, month, day, hour, minute ->
                val showMonth = if(month > 10 ) "$month" else "0$month"
                val showDay = if(day > 10 ) "$day" else "0$day"
                val showHour = if(hour > 10 ) "$hour" else "0$hour"
                val showMinute = if(minute > 10 ) "$minute" else "0$minute"
                activityMainBinding.tvTime.text = "${year}年${showMonth}月${showDay}日${showHour}时${showMinute}分"
            }
        }
    }

}